package br.edu.ufcg.ga.stopcondition;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

public class HybridStopConditionTest {

	private HybridStopCondition hsc;

	@Before
	public void setUp() throws Exception {
		this.hsc = new HybridStopCondition(10, 3);
	}

	@Test
	public void testReachedStopConditionMaxIterations() {
		int generation = 1;
		double bestFitness = 100.0;

		for (; generation < 10; generation++) {
			assertFalse(this.hsc.reached(generation, bestFitness--));
		}

		assertTrue(this.hsc.reached(generation, bestFitness));
	}

	@Test
	public void testReachedStopConditionMaxRepetitionBestFitness() {
		int generation = 1;

		for (int i = 0; i < 1; i++) {
			assertFalse(this.hsc.reached(generation++, 160.0));
		}

		for (int i = 0; i < 2; i++) {
			assertFalse(this.hsc.reached(generation++, 155.0));
		}

		for (int i = 0; i < 3; i++) {
			assertFalse(this.hsc.reached(generation++, 150.0));
		}
		assertTrue(this.hsc.reached(generation++, 150.0));
	}

}
